<?php
// +---------------------------------------------------------------------+
// | OneBase    | [ WE CAN DO IT JUST THINK ]                            |
// +---------------------------------------------------------------------+
// | Licensed   | http://www.apache.org/licenses/LICENSE-2.0 )           |
// +---------------------------------------------------------------------+
// | Author     | Bigotry <3162875@qq.com>                               |
// +---------------------------------------------------------------------+
// | Repository | https://gitee.com/Bigotry/OneBase                      |
// +---------------------------------------------------------------------+

namespace app\admin\controller;

use app\common\model\GamblerKing;
use app\common\model\OtcOrder;
use app\common\model\Transfer;
use app\common\model\UserKingInvestment;

/**
 * 首页控制器
 */
class Index extends AdminBase
{
    
    /**
     * 首页方法
     */
    public function index()
    {
        

        
        return $this->fetch('index');
    }

    /**
     * 首页方法
     */
    public function welcome()
    {

        // 获取首页数据
        $index_data = $this->logicAdminBase->getIndexData();
        $count_data=[];
        $count_data['user_data']=[
                \app\common\model\Member::where(['create_time'=>['between',[getTodayStart(),getTodayEnd()]],'is_inside'=>0])->count(),
                \app\common\model\Member::where(['create_time'=>['between',[getTodayStart()-86400,getTodayEnd()]],'is_inside'=>0])->count(),
                \app\common\model\Member::where(['create_time'=>['between',[getTodayStart()-86400*3,getTodayEnd()]],'is_inside'=>0])->count(),
                \app\common\model\Member::where(['create_time'=>['between',[getTodayStart()-86400*7,getTodayEnd()]],'is_inside'=>0])->count(),
                \app\common\model\Member::where(['create_time'=>['between',[getTodayStart()-86400*15,getTodayEnd()]],'is_inside'=>0])->count(),
                \app\common\model\Member::where(['create_time'=>['between',[getTodayStart()-86400*30,getTodayEnd()]],'is_inside'=>0])->count(),
                \app\common\model\Member::where(['is_inside'=>0])->count()
        ];
        $count_data['king_data']=[
            GamblerKing::where(['update_time'=>['between',[getTodayStart(),getTodayEnd()]],'state'=>2])->count(),
            GamblerKing::where(['update_time'=>['between',[getTodayStart()-86400,getTodayEnd()]],'state'=>2])->count(),
            GamblerKing::where(['update_time'=>['between',[getTodayStart()-86400*3,getTodayEnd()]],'state'=>2])->count(),
            GamblerKing::where(['update_time'=>['between',[getTodayStart()-86400*7,getTodayEnd()]],'state'=>2])->count(),
            GamblerKing::where(['update_time'=>['between',[getTodayStart()-86400*15,getTodayEnd()]],'state'=>2])->count(),
            GamblerKing::where(['update_time'=>['between',[getTodayStart()-86400*30,getTodayEnd()]],'state'=>2])->count(),
            GamblerKing::where(['state'=>2])->count()
        ];
        $count_data['shop_data']=[
            \app\common\model\OtcShop::where(['update_time'=>['between',[getTodayStart(),getTodayEnd()]],'state'=>2])->count(),
            \app\common\model\OtcShop::where(['update_time'=>['between',[getTodayStart()-86400,getTodayEnd()]],'state'=>2])->count(),
            \app\common\model\OtcShop::where(['update_time'=>['between',[getTodayStart()-86400*3,getTodayEnd()]],'state'=>2])->count(),
            \app\common\model\OtcShop::where(['update_time'=>['between',[getTodayStart()-86400*7,getTodayEnd()]],'state'=>2])->count(),
            \app\common\model\OtcShop::where(['update_time'=>['between',[getTodayStart()-86400*15,getTodayEnd()]],'state'=>2])->count(),
            \app\common\model\OtcShop::where(['update_time'=>['between',[getTodayStart()-86400*30,getTodayEnd()]],'state'=>2])->count(),
            \app\common\model\OtcShop::where(['state'=>2])->count()
        ];
        $count_data['user_entrust_hand_data']=[
           UserKingInvestment::where(['update_time'=>['between',[getTodayStart(),getTodayEnd()]],'state'=>2])->sum('money')+0,
           UserKingInvestment::where(['update_time'=>['between',[getTodayStart()-86400,getTodayEnd()]],'state'=>2])->sum('money')+0,
           UserKingInvestment::where(['update_time'=>['between',[getTodayStart()-86400*3,getTodayEnd()]],'state'=>2])->sum('money')+0,
           UserKingInvestment::where(['update_time'=>['between',[getTodayStart()-86400*7,getTodayEnd()]],'state'=>2])->sum('money')+0,
           UserKingInvestment::where(['update_time'=>['between',[getTodayStart()-86400*15,getTodayEnd()]],'state'=>2])->sum('money')+0,
           UserKingInvestment::where(['update_time'=>['between',[getTodayStart()-86400*80,getTodayEnd()]],'state'=>2])->sum('money')+0,
           UserKingInvestment::where(['state'=>2])->sum('money')+0
        ];
        $count_data['user_entrust_end_data']=[
            UserKingInvestment::where(['create_time'=>['between',[getTodayStart(),getTodayEnd()]],'state'=>0])->sum('money')+0,
            UserKingInvestment::where(['create_time'=>['between',[getTodayStart()-86400,getTodayEnd()]],'state'=>0])->sum('money')+0,
            UserKingInvestment::where(['create_time'=>['between',[getTodayStart()-86400*3,getTodayEnd()]],'state'=>0])->sum('money')+0,
            UserKingInvestment::where(['create_time'=>['between',[getTodayStart()-86400*7,getTodayEnd()]],'state'=>0])->sum('money')+0,
            UserKingInvestment::where(['create_time'=>['between',[getTodayStart()-86400*15,getTodayEnd()]],'state'=>0])->sum('money')+0,
            UserKingInvestment::where(['create_time'=>['between',[getTodayStart()-86400*80,getTodayEnd()]],'state'=>0])->sum('money')+0,
            UserKingInvestment::where(['state'=>0])->sum('money')+0
        ];
        $count_data['recharge_data']=[
           Transfer::where(['update_time'=>['between',[getTodayStart(),getTodayEnd()]],'state'=>1,'type'=>['in',[4,10]]])->sum('money')+0,
           Transfer::where(['update_time'=>['between',[getTodayStart()-86400,getTodayEnd()]],'state'=>1,'type'=>['in',[4,10]]])->sum('money')+0,
           Transfer::where(['update_time'=>['between',[getTodayStart()-86400*3,getTodayEnd()]],'state'=>1,'type'=>['in',[4,10]]])->sum('money')+0,
           Transfer::where(['update_time'=>['between',[getTodayStart()-86400*7,getTodayEnd()]],'state'=>1,'type'=>['in',[4,10]]])->sum('money')+0,
           Transfer::where(['update_time'=>['between',[getTodayStart()-86400*15,getTodayEnd()]],'state'=>1,'type'=>['in',[4,10]]])->sum('money')+0,
           Transfer::where(['update_time'=>['between',[getTodayStart()-86400*30,getTodayEnd()]],'state'=>1,'type'=>['in',[4,10]]])->sum('money')+0,
           Transfer::where(['state'=>1,'type'=>['in',[4,10]]])->sum('money')+0
        ];
        $count_data['withdrwal_data']=[
            Transfer::where(['update_time'=>['between',[getTodayStart(),getTodayEnd()]],'state'=>1,'type'=>['in',[3,20]]])->sum('money')+0,
            Transfer::where(['update_time'=>['between',[getTodayStart()-86400,getTodayEnd()]],'state'=>1,'type'=>['in',[3,20]]])->sum('money')+0,
            Transfer::where(['update_time'=>['between',[getTodayStart()-86400*3,getTodayEnd()]],'state'=>1,'type'=>['in',[3,20]]])->sum('money')+0,
            Transfer::where(['update_time'=>['between',[getTodayStart()-86400*7,getTodayEnd()]],'state'=>1,'type'=>['in',[3,20]]])->sum('money')+0,
            Transfer::where(['update_time'=>['between',[getTodayStart()-86400*15,getTodayEnd()]],'state'=>1,'type'=>['in',[3,20]]])->sum('money')+0,
            Transfer::where(['update_time'=>['between',[getTodayStart()-86400*30,getTodayEnd()]],'state'=>1,'type'=>['in',[3,20]]])->sum('money')+0,
            Transfer::where(['state'=>1,'type'=>['in',[3,20]]])->sum('money')+0
        ];
        $count_data['otc_data']=[
            OtcOrder::where(['create_time'=>['between',[getTodayStart(),getTodayEnd()]],'state'=>2])->sum('total')+0,
            OtcOrder::where(['create_time'=>['between',[getTodayStart()-86400,getTodayEnd()]],'state'=>2])->sum('total')+0,
            OtcOrder::where(['create_time'=>['between',[getTodayStart()-86400*3,getTodayEnd()]],'state'=>2])->sum('total')+0,
            OtcOrder::where(['create_time'=>['between',[getTodayStart()-86400*7,getTodayEnd()]],'state'=>2])->sum('total')+0,
            OtcOrder::where(['create_time'=>['between',[getTodayStart()-86400*15,getTodayEnd()]],'state'=>2])->sum('total')+0,
            OtcOrder::where(['create_time'=>['between',[getTodayStart()-86400*30,getTodayEnd()]],'state'=>2])->sum('total')+0,
            OtcOrder::where(['state'=>2])->sum('total')+0
        ];
        $count_data['game_data']=[
            Transfer::where(['update_time'=>['between',[getTodayStart(),getTodayEnd()]],'state'=>1,'type'=>8])->sum('money')+0,
            Transfer::where(['update_time'=>['between',[getTodayStart()-86400,getTodayEnd()]],'state'=>1,'type'=>8])->sum('money')+0,
            Transfer::where(['update_time'=>['between',[getTodayStart()-86400*3,getTodayEnd()]],'state'=>1,'type'=>8])->sum('money')+0,
            Transfer::where(['update_time'=>['between',[getTodayStart()-86400*7,getTodayEnd()]],'state'=>1,'type'=>8])->sum('money')+0,
            Transfer::where(['update_time'=>['between',[getTodayStart()-86400*15,getTodayEnd()]],'state'=>1,'type'=>8])->sum('money')+0,
            Transfer::where(['update_time'=>['between',[getTodayStart()-86400*30,getTodayEnd()]],'state'=>1,'type'=>8])->sum('money')+0,
            Transfer::where(['state'=>1,'type'=>8])->sum('money')+0
        ];

//        dd(json_encode($count_data,JSON_UNESCAPED_UNICODE));
        $this->assign('count_data',$count_data );
        $this->assign('info', $index_data);

        return $this->fetch();
    }
}
